<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <FilterTable
      ref="table"
      columnsRef="testindex"
      :isExportExcel2="true"
      exportFileName="PDI接车维护.xlsx"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="false"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
      <template slot="controls">
        <el-button v-show=flag size="small" type="primary" icon="el-icon-plus" @click="detailHandle(null,'add')">新增</el-button>
      </template>
    </FilterTable>

    <!-- 编辑窗口 -->
    <Drawer
      :visible.sync="visibleDrawer"
      title="接车PDI维护"
      :width="1200"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-model v-model="initData" @close="infoClose" />
    </Drawer>
  </div>
</template>

<script>
import infoModel from './info';
import { getCheckingData,getdeal } from '@/api/serviceass/pdimanage/meetingcar';
import { dictionary } from '@/utils/dictMixin';
import { getAllUser } from '@/api/customerRepair/activityVisit/resultEntry/index';
export default {
  name: 'servicessbpdimanagemeetingcarindex',
  mixins: [dictionary],
  components: {
    infoModel
  },
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchParams: { xhrAbort: true },
      visibleDrawer: false,
      fetchApi: getCheckingData,
      initData: {},
      flag:false
    }
  },
  created() {
    this.initColunm()
    this.findUser()
  },
  methods: {
    async initColunm() {
      let res= await getAllUser();
      this.columns.find(x => x.dataIndex == 'fwclry').dictItems = res.data.map(x => ({text: x.employeeName, value: x.userId}));
      this.columns.find(x => x.dataIndex == 'fwdjzt').dictItems = this.createDictList('5010')
      this.columns.find(x => x.dataIndex == 'fwdjlx').dictItems = this.createDictList('5009')
    },
    findUser(){
      getdeal({}).then(res=>{
        this.flag=res.data.appId==='beijing'? false:true
        if (this.flag){
          this.columns.find(x => x.dataIndex == 'dealerCode').hidden = false
          this.columns.find(x => x.dataIndex == 'dealerName').hidden = false
        }else{
          this.columns.find(x => x.dataIndex == 'dealerCode').hidden = true
          this.columns.find(x => x.dataIndex == 'dealerName').hidden = true
        }
      })
    },
    createTopFilterList() {
      return [
        {
          type: 'RANGE_DATE',
          label: '创建日期',
          fieldName: 'createdAt1|createdAt2',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: 'VIN:',
          fieldName: 'fwvinm'
        },
        {
          type: 'SELECT',
          label: '状态:',
          fieldName: 'fwdjzt',
          placeholder: '请选择...',
          itemList: this.createDictList('5010')
        },
      ]
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
              <multiuse-button  disabled={props.row.fwdjzt === 50101002} size="mini" type="text" onClick={() => this.detailHandle(props.row, 'edit')}>
                编辑
              </multiuse-button>
             <multiuse-button  disabled={ props.row.fwdjzt === 50101001} size="mini" type="text" onClick={() => this.detailHandle(props.row, 'edit')}>
                查看
            </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '状态',
          dataIndex: 'fwdjzt',
          sorter: true,
          showOverflowTooltip: true,
          render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.fwdjzt, '5010')}</span>;
          }
        },
        {
          title: 'PDI类型',
          dataIndex: 'fwdjlx',
          sorter: true,
          showOverflowTooltip: true,
          render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.fwdjlx, '5009')}</span>;
          }
        },
        {
          title: '经销商/交付中心代码',
          dataIndex: 'dealerCode',
          sorter: true,
          hidden: false,
        },
        {
          title: '经销商/交付中心名称',
          dataIndex: 'dealerName',
          sorter: true,
          hidden:false,
        },
        {
          width: 150,
          title: 'VIN',
          dataIndex: 'fwvinm',
          sorter: true,
        },
        {
          title: '车型',
          dataIndex: 'fwchex',
          sorter: true,
        },
        {
          title: '生产日期',
          dataIndex: 'fwscrq',
          sorter: true,
          dateFormat: 'yyyy-MM-dd hh:mm:ss',
        },
        {
          title: '发动机号/电机号',
          dataIndex: 'fwfdjh',
          sorter: true,
        },
        // {
        //   title: '处理人',
        //   dataIndex: 'fwclryStr',
        //   sorter: true,
        // },
        {
          title: '处理时间',
          dataIndex: 'fwclsj',
          sorter: true,
          dateFormat: 'yyyy-MM-dd hh:mm:ss',
        },
        {
          title: '操作时间',
          dataIndex: 'updatedAt',
          sorter: true,
          dateFormat: 'yyyy-MM-dd hh:mm:ss',
        }
      ]
    },
    changeHandle(val) {
      // this.fetchParams = Object.assign({}, val);
      val.createdAt2 && (val.createdAt2 = val.createdAt2.split(' ')[0] + ' 23:59:59');
      this.fetchParams = Object.assign({}, val, { fwdjlx: '50091001', xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectData(val) {
      this.tableData = val;
    },
    detailHandle(row, type) {
      if (type!=='add'&& row.fwdjzt === 50101002) {
        type = 'show'
      }
      this.initData =  {
        type: type,
        data: row,
        id:1001
      }; //行id
      this.visibleDrawer = true;
    },
    infoClose(rData) {
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
  }
}
</script>
